package com.kz.controller;

import com.kz.service.IYCREService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

@RestController
public class YCRExcelController {
    private static Logger logger = LogManager.getLogger(YCRExcelController.class);
    @Resource
    private IYCREService iycreService;

    @PostMapping("/import")
    public Object upload(@RequestParam("file") MultipartFile file) throws Exception {
        return iycreService.upload(file);
    }

    @GetMapping("/export")
    public Object export(HttpServletRequest request, HttpServletResponse response, @RequestParam("ids") String ids) throws Exception {
        List<String> list = Arrays.asList(ids.split(","));

        return iycreService.export(request, response, list);
    }
    /*@PostMapping("/export")
    public Object export(HttpServletRequest request, HttpServletResponse response, Map<String, List<String>> map) throws Exception {
        return iycreService.export(request, response, map.get("ids"));
    }*/
}
